package com.example.myproject.controller;

import com.example.myproject.dto.CommentReportDTO;
import com.example.myproject.dto.CommonResponse;
import com.example.myproject.dto.report.ReportRequest;
import com.example.myproject.dto.report.ReportResponse;
import com.example.myproject.service.ReportService;
import com.example.myproject.vo.ApiResponse;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/values/comments")
public class ReportController {

    @Autowired
    private ReportService reportService;

    @PostMapping("/{commentId}/report")
    public CommonResponse<ReportResponse> reportComment(
            @PathVariable("commentId") Long commentId,
            @RequestBody ReportRequest req) {

        ReportResponse resp = reportService.reportComment(commentId, req);
        return CommonResponse.success(resp);
    }

    // 获取被举报列表
    @PreAuthorize("hasRole('ADMIN')")
    @GetMapping("/report/pending")
    public ApiResponse<List<CommentReportDTO>> getPendingReports() {
        List<CommentReportDTO> list = reportService.getPendingReports();
        return ApiResponse.success(200, "获取成功", list);
    }



    // 管理员处理举报并封禁用户
    @PreAuthorize("hasRole('ADMIN')")
    @PostMapping("/report/handle")
    public ApiResponse<String> handleReportAndBanUser(@RequestBody HandleReportRequest request) {
        System.out.println(request);
        reportService.handleReportAndBanUser(request.getReportId(), request.getUserId(), request.getCommentId());
        return ApiResponse.success(200, "处理成功", null);
    }
    @Data
    public static class HandleReportRequest {
        private Long reportId;
        private Long userId;
        private Long commentId;
    }


}